package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleMenuService;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/2
 * description：
 */
@RestController
@RequestMapping("/admin/system/roleMenu")
@Tag(name = "角色菜单管理模块")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    //查询指定角色拥有的菜单id
    @GetMapping("/getMenusByRoleId/{roleId}")
    @Operation(summary = "查询指定角色的菜单接口")
    public Result assignMenu(@PathVariable Long roleId) {
        List<Long> menuIds = sysRoleMenuService.getMenusByRoleId(roleId);
        return Result.ok(menuIds);
    }


    //分配菜单
    @PutMapping("/assignMenus/{roleId}")
    @Operation(summary = "分配菜单接口")
    public Result assignMenus(
            @PathVariable Long roleId,
            @RequestBody List<Long> menuIds) {
        sysRoleMenuService.assignMenus(roleId, menuIds);
        return Result.ok();
    }
}
